package com.yc.op.core.message;
import com.yc.op.core.message.PBMessage.*;
import com.yc.op.core.message.PBMessage;
import com.google.protobuf.InvalidProtocolBufferException;
import com.hutong.framework.convert.IConvert;
public class PBConvert implements IConvert {
	public Object toObject(int opcode, byte[] objectBytes) throws InvalidProtocolBufferException {
		Object result = null;
		switch (opcode) {
			case OpDefine.CSCreateRoom:
				result=PBMessage.CSCreateRoom.parseFrom(objectBytes);
				break;
			case OpDefine.CSEnterRoom:
				result=PBMessage.CSEnterRoom.parseFrom(objectBytes);
				break;
			case OpDefine.CSLeaveRoom:
				result=PBMessage.CSLeaveRoom.parseFrom(objectBytes);
				break;
			case OpDefine.CSRoomList:
				result=PBMessage.CSRoomList.parseFrom(objectBytes);
				break;
			case OpDefine.SCRoomList:
				result=PBMessage.SCRoomList.parseFrom(objectBytes);
				break;
			case OpDefine.SCCreateRoomSuccess:
				result=PBMessage.SCCreateRoomSuccess.parseFrom(objectBytes);
				break;
			case OpDefine.SCEnterRoomSuccess:
				result=PBMessage.SCEnterRoomSuccess.parseFrom(objectBytes);
				break;
			case OpDefine.SCLeaveRoomSuccess:
				result=PBMessage.SCLeaveRoomSuccess.parseFrom(objectBytes);
				break;
			case OpDefine.SCFightReady:
				result=PBMessage.SCFightReady.parseFrom(objectBytes);
				break;
			case OpDefine.SCFightEnd:
				result=PBMessage.SCFightEnd.parseFrom(objectBytes);
				break;
			case OpDefine.SCRoundStart:
				result=PBMessage.SCRoundStart.parseFrom(objectBytes);
				break;
			case OpDefine.SCRoundEnd:
				result=PBMessage.SCRoundEnd.parseFrom(objectBytes);
				break;
			case OpDefine.CSUseSkill:
				result=PBMessage.CSUseSkill.parseFrom(objectBytes);
				break;
			case OpDefine.SCUseSkill:
				result=PBMessage.SCUseSkill.parseFrom(objectBytes);
				break;
			default:
				result = null;
				break;
		}
		return result;
	}
	public byte[] toBytes(int opcode, Object object) {
		byte[] objectBytes = null;
		switch (opcode) {
			case OpDefine.CSCreateRoom:
			    objectBytes = ((CSCreateRoom) object).toByteArray();
			    break;
			case OpDefine.CSEnterRoom:
			    objectBytes = ((CSEnterRoom) object).toByteArray();
			    break;
			case OpDefine.CSLeaveRoom:
			    objectBytes = ((CSLeaveRoom) object).toByteArray();
			    break;
			case OpDefine.CSRoomList:
			    objectBytes = ((CSRoomList) object).toByteArray();
			    break;
			case OpDefine.SCRoomList:
			    objectBytes = ((SCRoomList) object).toByteArray();
			    break;
			case OpDefine.SCCreateRoomSuccess:
			    objectBytes = ((SCCreateRoomSuccess) object).toByteArray();
			    break;
			case OpDefine.SCEnterRoomSuccess:
			    objectBytes = ((SCEnterRoomSuccess) object).toByteArray();
			    break;
			case OpDefine.SCLeaveRoomSuccess:
			    objectBytes = ((SCLeaveRoomSuccess) object).toByteArray();
			    break;
			case OpDefine.SCFightReady:
			    objectBytes = ((SCFightReady) object).toByteArray();
			    break;
			case OpDefine.SCFightEnd:
			    objectBytes = ((SCFightEnd) object).toByteArray();
			    break;
			case OpDefine.SCRoundStart:
			    objectBytes = ((SCRoundStart) object).toByteArray();
			    break;
			case OpDefine.SCRoundEnd:
			    objectBytes = ((SCRoundEnd) object).toByteArray();
			    break;
			case OpDefine.CSUseSkill:
			    objectBytes = ((CSUseSkill) object).toByteArray();
			    break;
			case OpDefine.SCUseSkill:
			    objectBytes = ((SCUseSkill) object).toByteArray();
			    break;
         default:
             objectBytes = null;
             break;
		}
		return objectBytes;
 }
}
